package com.example.clientmessage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class ContactActivity extends Activity {

	public static final String CELL_NO = "cellNo";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_contact);
		// TableRow tableRow = (TableRow)findViewById(R.id.tableRow);

		TableRow tr1;
		// TableRow tr2;
		TextView txt9;

		TableLayout tl = (TableLayout) findViewById(R.id.myLayout);
		Display display = getWindowManager().getDefaultDisplay();
		int width = display.getWidth();

		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
				width, LayoutParams.FILL_PARENT);

		for (int i = 0; i < 20; i++) {

			tr1 = (TableRow) new TableRow(this);
			// txt9=new TextView(this);
			// txt9.setText("test" + i);

			Contact newContact = new Contact(this);
			newContact.setText("test" + i);
			newContact.setNumber(String.valueOf(i));
			newContact.setName("test" + i);
			newContact.setOnClickListener(btnclick);
			tr1.addView(newContact);
			// tr1.addView(txt9);
			tl.addView(tr1, new TableLayout.LayoutParams(layoutParams));
		}
	}

	Button.OnClickListener btnclick = new Button.OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub

			Contact button = (Contact) v;
			// Toast.makeText(getApplicationContext(),
			// button.getText().toString(), 2).show();
			
			// create Intent here
			Intent intent = new Intent(v.getContext(), ChatActivity.class);

			intent.putExtra(CELL_NO, button.getNumber());
			startActivity(intent);
		}

	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_contact, menu);
		return true;
	}

}
